﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "ui_mainwindow.h"

#include "mqtt/qmqtt.h"

#include <QtNetwork>
#include <QHostAddress>

#include <QTimer>

#include "qcustomplot.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>


#include "videoshow.h"
#include "v4l2_thread.h"


#include "myhelper.h"


#include <QSerialPort>        //提供访问串口的功能
#include <QSerialPortInfo>    //提供系统中存在的串口的信息

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    QMQTT::Client *client; // 创建QMQTT 客户端

    QCustomPlot *dataCustomPlot;

    QTimer *mainTimer;                  //主时钟定时器

    QTimer *myReadTimer;


    videoshow   *video;

    V4l2Thread *V4l2_T;

    int fd=0;

    int sgp30_fd=0;

    int now_time = 0;

    bool show_temp_humi = false;
    bool show_co2_tvoc = false;
    bool show_pm2_5    = false;

    float temp,humi;
    int CO2_data,TVOC_data;
    int PM_2_5_data, PM10_data;

private:
    Ui::MainWindow *ui;

    void clientMqtt();

    void sht20_Init();

    void dataCustomPlotInit();

    void read_Sht20_data();

    void sgp30_init();

    void read_sgp30_data();

    void usartDataInit();

private slots:
   void onMQTT_Received(QMQTT::Message);
   void onMQTT_subscribed( QString, quint8);
   void onMQTT_unSubscribed( QString );

   void read_sensor_data();

   void receiveInfo();

   void on_pushButton_clicked();
   void on_comboBox_currentIndexChanged(int index);
};
#endif // MAINWINDOW_H
